#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);
  QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(addNumber()));
  QObject::connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(sumNumbers()));
  QObject::connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(clearNumbers()));
}

void MainWindow::addNumber() {
  numbers.append(LongNumber(ui->lineEdit->text()));
  ui->listWidget->addItem(numbers.last().toString());
}

void MainWindow::sumNumbers() {
  LongNumber result("");
  foreach (LongNumber number, numbers) {
    result += number;
  }
  numbers.append(result);
  ui->listWidget->addItem(result.toString());
}

void MainWindow::clearNumbers() {
  ui->listWidget->clear();
  numbers.clear();
}

MainWindow::~MainWindow() {
  delete ui;
}
